package com.aftersale.demo.controller;

import com.aftersale.demo.entity.*;
import com.aftersale.demo.service.ProblemService;
import com.aftersale.demo.service.SolveService;
import com.aftersale.demo.utils.ValidGroup;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author 空
 * @date 2023/11/21 14:21
 * @desc
 */
@Api(tags = "问题解决模块")
@RestController
@RequestMapping("/solve")
public class SolveController {

    @Autowired
    ProblemService problemService;
    @Autowired
    SolveService solveService;

    @GetMapping("/getproblem")
    @ApiOperation(value = "个人售后问题查看接口")
    public Result getproblem(@RequestParam int userId,
                           @RequestParam Integer pageNum,
                           @RequestParam Integer pageSize){
        return problemService.getProblem(userId,pageNum,pageSize);
    }

    @GetMapping("/selectproblem")
    @ApiOperation(value = "个人售后问题搜索接口")
    public Result selectproblem(@RequestParam int userId,
                                @RequestParam String name,
                                @RequestParam Integer pageNum,
                                @RequestParam Integer pageSize){
        return problemService.selectProblem(userId,name,pageNum,pageSize);
    }

    @GetMapping("/getmysolve")
    @ApiOperation(value = "解决方案查看接口")
    public Result getMySolve(@RequestParam int problemId){
        return solveService.getMySolve(problemId);
    }

    @DbLog(operation = "解决方案",type = LogType.ADD)
    @PostMapping("/addsolve")
    @ApiOperation("提交解决方案")
    @PreAuthorize("hasAuthority('solve')")
    public Result addSolve(@Validated Solve solve){
        return solveService.addSolve(solve);
    }



    @DbLog(operation = "解决方案",type = LogType.UPDATE)
    @PutMapping("/updatesolve")
    @ApiOperation("修改解决方案")
    @PreAuthorize("hasAuthority('solve')")
    public Result updateSolve(@Validated Solve solve){
        return solveService.updateSolve(solve);
    }

    @DbLog(operation = "解决方案",type = LogType.DELETE)
    @DeleteMapping("/deletemysolve")
    @PreAuthorize("hasAuthority('solve')")
    @ApiOperation(value = "解决方案删除接口")
    public Result deleteMySolve(@RequestParam int solveId){
        return solveService.deleteSolve(solveId);
    }
}
